package com.lcf.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.lcf.framework.utils.UserUtils;
import com.lcf.system.dao.SysUserDao;
import com.lcf.system.dto.user.SysUserEditDTO;
import com.lcf.system.entity.SysUser;
import com.lcf.system.service.SysUserService;
import com.lcf.system.vo.user.SysUserVO;
import org.springframework.stereotype.Service;

/**
 * 用户表(User)表服务实现类
 *
 * @author lcf
 * @since 2025-02-19 13:27:56
 */
@Service("userService")
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUser> implements SysUserService {
    @Override
    public void edit(SysUserEditDTO dto) {
        Db.lambdaQuery(SysUser.class).eq(SysUser::getOpenId, UserUtils.getOpenId()).oneOpt().ifPresent(user -> {
            SysUser sysUser = BeanUtil.copyProperties(dto, SysUser.class);
            sysUser.setId(user.getId());
            sysUser.updateById();
        });
    }

    @Override
    public SysUserVO getMyInfo() {
        SysUser sysUser = getById(UserUtils.getId());
        return BeanUtil.copyProperties(sysUser, SysUserVO.class);
    }
}
